package com.xpffly.design.proxy.force;

import com.xpffly.design.proxy.force.service.GamePlayer;
import com.xpffly.design.proxy.force.service.impl.GamePlayerProxy;
import com.xpffly.design.proxy.force.service.impl.GamePlayerReal;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: xpengfei
 * @Date: 2021/3/30 21:55
 * @Description：强制代理场景类
 */
public class Scene {
    public static void main(String[] args) {
        realRole();
        System.out.println("-----------------------------");
        proxyRole();
        System.out.println("-----------------------------");
        targetProxy();
    }

    /**
     * 直接访问真实角色
     */
    public static void realRole() {
        // 定义游戏角色
        GamePlayer gamePlayer = new GamePlayerReal("张三");

        System.out.println("游戏开始时间是：" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        //登录
        gamePlayer.login("zhangsan", "password");
        // 打怪
        gamePlayer.killBoss();
        // 升级
        gamePlayer.upgrade();
        System.out.println("游戏结束时间是：" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }

    /**
     * 直接访问代理类
     */
    public static void proxyRole() {
        // 定义游戏角色
        GamePlayer gamePlayer = new GamePlayerReal("张三");
        // 定义代练
        GamePlayer gamePlayerProxy = new GamePlayerProxy(gamePlayer);

        System.out.println("游戏开始时间是：" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        //登录
        gamePlayerProxy.login("zhangsan", "password");
        // 打怪
        gamePlayerProxy.killBoss();
        // 升级
        gamePlayerProxy.upgrade();
        System.out.println("游戏结束时间是：" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }

    /**
     * 使用指定的代理访问（强制代理访问）
     */
    public static void targetProxy() {
        // 定义游戏角色
        GamePlayer gamePlayer = new GamePlayerReal("张三");
        // 获取指定代理
        GamePlayer targetGamePlayerProxy = gamePlayer.getGamePlayerProxy();

        System.out.println("游戏开始时间是：" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        //登录
        targetGamePlayerProxy.login("zhangsan", "password");
        // 打怪
        targetGamePlayerProxy.killBoss();
        // 升级
        targetGamePlayerProxy.upgrade();
        System.out.println("游戏结束时间是：" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }


}
